home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
436_01
/
inalpha.c
< prev
next >
Wrap
Text File
|
1994-10-07
|
6KB
|
248 lines
/*************************************************************************
Source file: INALPHA.C
INCON alpha input handler.
Editor: Microsoft Works 1.0, Microsoft Word 4.0
Compiler: Borland Turbo C 2.01
INCON source files and the object and library files created from
them are:
Copyright (c) 1993-94, Richard Zigler.
You may freely distribute unmodified source, object, and library
files, and incorporate them into your own non-commercial software,
provided that this paragraph and the program name and copyright
strings defined in INCON.C are included in all copies.
*************************************************************************/
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include "indefs.h" /* globals and definitions */
#include "incon.h" /* state definitions */
#include "indecl.h" /* public utility routines */
int pascal hAlphaField( STATES State, register int Pos )
{
register int s_ptr;
int max_length = StrLength - 1,
max_width = Width - 1;
switch( State )
{
case stError:
break;
case stQuit: /* [Enter] -- end input */
Chr = StrLength < Prec ? -1 : 0 ;
More = NO;
break;
case stInit: /* field initialization */
if ( !Flags.Hide && !Flags.Scroll )
Pos = StrLength;
break;
case stFieldClear: /* [Esc] -- clear field or exit */
if ( EscSet || *OutStr == '\0' )
More = NO;
else
{
*OutStr = '\0';
Pos = StrLength = 0;
++Update;
}
break;
case stDeleteCharLeft: /* [Backspace] -- delete left */
if ( Pos )
{
if ( Pos > max_length )
{
putch( BS );
putch( Fill );
OutStr[--Pos] = '\0';
--StrLength;
--Move;
}
else if ( Pos == max_length )
goto __TruncateAtCursor;
else
{
--Pos;
goto __MoveCharsToCursor;
}
}
break;
case stMoveToStart: /* [Home] -- start of field */
if ( Pos )
{
Pos = 0;
--Move;
}
break;
case stMoveCharLeft: /* [Left Arrow] -- move char lt */
if ( Pos )
{
--Pos;
--Move;
}
break;
case stMoveCharRight: /* [Right Arrow] -- move char rt */
if ( Pos < StrLength && Pos < max_width )
{
++Pos;
++Move;
}
break;
case stMoveToEnd: /* [End] -- end of field */
if ( Pos < StrLength && Pos < max_width )
{
Pos = StrLength;
++Move;
}
break;
case stMoveWordLeft: /* [Ctrl Left] -- move word lt */
if ( Pos )
{
Pos = WordLeft( Pos, OutStr, ' ' );
--Move;
}
break;
case stMoveWordRight: /* [Ctrl Right] -- move word rt */
if ( Pos < StrLength && Pos < max_width )
{
Pos = WordRight( Pos, OutStr, ' ' );
++Move;
}
break;
case stDeleteWordLeft: /* [Ctrl L] -- delete word left */
if ( !Flags.Hide && Pos > (Flags.Scroll ? FieldMin + 1 : FieldMin) )
{
s_ptr = Pos;
Pos = WordLeft( Pos, OutStr, ' ' );
goto __DeleteWord;
}
break;
case stDeleteWordRight: /* [Ctrl R] -- delete word right */
if ( !Flags.Hide && Pos < StrLength )
{
s_ptr = WordRight( Pos, OutStr, ' ' );
__DeleteWord:
;
memcpy( OutStr + Pos, OutStr + s_ptr, StrLength - s_ptr + 1 );
StrLength -= (s_ptr - Pos);
++Update;
}
break;
case stDeleteToEnd: /* [Ctrl End] -- clear to end */
if ( Pos < StrLength )
goto __TruncateAtCursor;
break;
case stDeleteToStart: /* [Ctrl Home] -- clear to start */
if ( Pos )
{
memcpy( OutStr, OutStr + Pos, StrLength - Pos + 1 );
StrLength -= Pos;
Pos = 0;
++Update;
}
break;
case stDeleteAtCursor: /* [Del] -- delete at cursor */
if ( StrLength )
{
if ( Pos < max_length )
{
__MoveCharsToCursor:
;
memcpy( OutStr + Pos, OutStr + Pos + 1, StrLength - Pos );
--StrLength;
++Update;
}
else if ( Pos == max_length )
{
__TruncateAtCursor:
;
OutStr[Pos] = '\0';
StrLength = Pos;
++Update;
}
}
break;
case stExitPlus: /* [Keypad +] -- special exit */
case stExitMinus: /* [Keypad -] -- special exit */
/* convert to + or - and fall through to stCharMatch */
Chr = (State == stExitPlus) ? '+' : '-' ;
case stCharMatch: /* see if entry matches field */
if ( !iscntrl( Chr ) )
{
if ( Flags.Type == UPPER )
Chr = toupper( Chr ); /* convert alpha to uppercase */
if ( InBegin ) /* if first character entered */
{
*(WORD *)OutStr = Chr; /* put Chr and '\0' */
StrLength = Pos = 1;
if ( Flags.Hide ) /* if hidden input, */
putch( ' ' ); /* update display */
++Update;
}
else if ( Pos == StrLength || Pos == max_width ) /* at end */
{
if ( StrLength >= Width ) /* at max */
--StrLength;
putch( Flags.Hide ? ' ' : Chr );
*(WORD *)(OutStr + Pos++) = Chr;
++StrLength;
++Update;
}
else if ( StrLength < Width ) /* cursor within string */
{
memmove(OutStr + Pos + 1,OutStr + Pos,StrLength - Pos + 1);
OutStr[Pos++] = (char)Chr;
++StrLength;
++Update;
} /* else (InBegin) */
} /* if (!iscntrl()) */
else
State = stError;
break;
} /* switch() */
if ( Pos >= Width )
Pos = Width - 1;
return( Pos );
}
/**** EOF: INALPHA.C ****/